package proxy.jdk;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Proxy;

public class MyProxyTest {

	public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

		System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
//		Class<?> proxy = Proxy.getProxyClass(IHelloWorld.class.getClassLoader(), IHelloWorld.class);
//		Constructor<?> constructor = proxy.getConstructor(InvocationHandler.class);
//		IHelloWorld iHelloWorld = (IHelloWorld) constructor.newInstance(new MyInvocationHandler(new HelloWorldImpl()));
//		iHelloWorld.sayHello();
//
		IHelloWorld iHelloWorld1 = (IHelloWorld) Proxy.newProxyInstance(
				IHelloWorld.class.getClassLoader(),
				new Class[]{IHelloWorld.class},
				new MyInvocationHandler(new HelloWorldImpl()));
		iHelloWorld1.sayHello();

		IHelloWorld iHelloWorld2 = (IHelloWorld) Proxy.newProxyInstance(
				IHelloWorld.class.getClassLoader(),
				new Class[]{IHelloWorld.class},
				new MyInvocationHandler(new HelloWorldImpl()));
		iHelloWorld2.sayHello();

	}
}
